package com.gzhuxj201.controller;

import com.github.pagehelper.PageHelper;
import com.gzhuxj201.entity.PageBean;
import com.gzhuxj201.entity.Result;
import com.gzhuxj201.entity.Student;
import com.gzhuxj201.entity.StudentDto;
import com.gzhuxj201.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/students")
@Slf4j
public class StudentController {
    @Autowired
    private StudentService studentService;


    @GetMapping("/selectUnsubmitStu")
    public Result selectUnsubmitStu(Integer id,String courseId){
        List<Student> studentList= studentService.selectUnsubmitStu(id,courseId);
        return Result.success(studentList);
    }

    @GetMapping
    public Result page(Integer page,Integer pageSize,String sno,String username,Short gender){
        PageBean pageBean = studentService.page(page, pageSize,sno,username,gender);

        return Result.success(pageBean);
    }

    @PostMapping
    public Result add(@RequestBody Student student){
        int res=studentService.add(student);
        return Result.success();
    }

    @GetMapping("{sno}")
    public Result selectById(@PathVariable String sno){
        StudentDto studentDto =studentService.selectById(sno);
        return Result.success(studentDto);
    }

    @PutMapping
    public Result update(@RequestBody Student student){
        int res=studentService.update(student);
        return Result.success();
    }

    @DeleteMapping("{ids}")
    public Result deleteByIds(@PathVariable List<Integer> ids){
        int res= studentService.deleteByIds(ids);
        return Result.success();
    }


}
